#pragma once
#include "detect_structure.h"

// 点迹凝聚器
class PlotAggregator
{
private:
    float range_threshold;
    float doppler_threshold;
    float angle_threshold;
    float power_threshold;

public:
    PlotAggregator(float range_thresh, float doppler_thresh,
                   float angle_thresh, float power_thresh)
        : range_threshold(range_thresh), doppler_threshold(doppler_thresh),
          angle_threshold(angle_thresh), power_threshold(power_thresh) {}

    // 点迹凝聚算法
    std::vector<TargetInfo> aggregate(const std::vector<DetectionCell> &detections,
                                      const RadarParameters &params);

private:
    // 判断两个点迹是否相邻
    bool isNeighbor(const DetectionCell &a, const DetectionCell &b,
                    const RadarParameters &params);
    ;
    // 计算目标参数
    TargetInfo computeTargetParameters(const std::vector<size_t> &cluster,
                                       const std::vector<DetectionCell> &detections,
                                       const RadarParameters &params);

    // 计算距离
    inline float calculateRange(int range_bin, const RadarParameters &params)
    {
        return range_bin * params.getRangeResolution();
    }

    // 计算速度
    inline float calculateVelocity(int doppler_bin, const RadarParameters &params)
    {
        float doppler_freq = (doppler_bin - params.num_pulses / 2) *
                             (1.0f / (params.num_pulses * params.pulse_rep_interval));
        return doppler_freq * params.light_speed / (2.0f * params.carrier_frequency);
    }

    // 计算角度
    inline float calculateAngle(int angle_bin, const RadarParameters &params)
    {
        return static_cast<float>(angle_bin) * 180.0f / params.num_antennas - 90.0f;
    }
};
